package cn.iocoder.yudao.framework.i18n.utils;

import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * @author Eric
 */
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MessageUtils {

//    private static MessageSource messageSource;
//    public MessageUtils(MessageSource messageSource) {
//        MessageUtils.messageSource = messageSource;
//    }
    private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class);

    public static String get(String key) {
        return MESSAGE_SOURCE.getMessage(key, null, LocaleContextHolder.getLocale());
    }

    public static String get(String key, Object arg) {
        return MESSAGE_SOURCE.getMessage(key, new Object[]{arg}, LocaleContextHolder.getLocale());
    }
}
